package com.cxso.example;

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.cxso.example.client.ReportClient;
import com.cxso.example.enums.report.*;
import com.cxso.example.request.report.*;
import com.cxso.example.sdk.SdkClient;
import com.cxso.example.sdk.domain.Result;
import com.cxso.example.sdk.http.client.ClientManager;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;


/**
 * 聚合上报示例
 */
public class ReportExample {

    public static final SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    //步骤一: 初始化客户端链接
    public static final ClientManager CLIENT_MANAGER = SdkClient.builder("服务域名地址", "clientId", "clientSecret");

    public static void main(String[] args) throws ParseException {
        //车辆上报
        reportCar();
        //司机上报
        reportDriver();
        //运单上报
        reportWaybill();
        //合同上报
        reportContract();
        //支付流水
        reportFinancial();
    }


    //车辆上报
    private static void reportCar() {
        //步骤二: 选择服务
        ReportClient reportClient = CLIENT_MANAGER.use(ReportClient.class);
        ReportCarRequest request = new ReportCarRequest();
        request.setBodyId("管理员分配的bodyId");
        request.setVehicleNumber("晋B11111");
        request.setVehiclePlateColorCode(CarColorEnum.YELLOW);
        request.setVehicleType(CarTypeEnum.Q11);
        request.setLicensePlateTypeCode(LicensePlateTypeEnum.LARGE);
        request.setOwner("张三");
        request.setOwnerSocialNumber("132456789");
        request.setUseCharacter("货运");
        request.setVin("LFXAH78W4M111111");
        request.setIssuingOrganizations("山西省大同市公安局交通警察支队");
        request.setRegisterDate("20210526");
        request.setIssueDate("20210526");
        request.setVehicleTo("203605");
        request.setVehicleEnergyType(VehicleEnergyTypeEnum.B);
        request.setVehicleLength("7.07");
        request.setVehicleTonnage("40.00");
        request.setGrossMass("48.87");
        request.setRoadTransportCertificateNumber("140000000000");
        request.setTrailerVehiclePlateNumber("晋B1111挂");
        request.setRemark("");
        request.setVehicleLicenseNumber("000000000000");
        request.setRoadTransportSocialCreditFrom("20210614");
        request.setRoadTransportSocialCreditTo("20260614");
        request.setVehicleLicenseFrontImg("https://file.test.com/test/nnrUidXV9f8U7nchU865ksWJN0BAM0DJ.png");
        request.setVehicleLicenseBackImg("https://file.test.com/test/nnrUidXV9f8U7nchU865ksWJN0BAM0DJ.png");
        request.setRoadTransportLicenseImg("https://file.test.com/test/nnrUidXV9f8U7nchU865ksWJN0BAM0DJ.png");
        request.setTrailerLicenseImg("https://file.test.com/test/nnrUidXV9f8U7nchU865ksWJN0BAM0DJ.png");
        request.setGroupPhotoImg("https://file.test.com/test/nnrUidXV9f8U7nchU865ksWJN0BAM0DJ.png");
        //步骤三: 调用服务

        Result<?> result = reportClient.reportCar(request);
        //步骤四: 拿到结果
        System.out.println(JSONObject.toJSONString(result, JSONWriter.Feature.PrettyFormat));
    }


    //司机上报
    private static void reportDriver() {
        //步骤二: 选择服务
        ReportClient reportClient = CLIENT_MANAGER.use(ReportClient.class);
        ReportDriverRequest request = new ReportDriverRequest();
        request.setBodyId("管理员分配的bodyId");
        request.setDriverName("张三");
        request.setDrivingLicense("140225199912124612");
        request.setVehicleClass("A1A2");
        request.setIssuingOrganizations("山西省大同市公安局交通警察支队");
        request.setValidPeriodFrom("20140929");
        request.setValidPeriodTo("20240929");
        request.setQualificationCertificate("140225199912124612");
        request.setQualificationCertificateFrom("20210504");
        request.setQualificationCertificateTo("20280504");
        request.setTelephone("18612345678");
        request.setRemark("");
        request.setIdCardFrontImg("https://file.test.com/test/oxG12YsjYHryHGYF2eBUoH4LPsGq7JDs.jpg");
        request.setIdCardBackImg("https://file.test.com/test/oxG12YsjYHryHGYF2eBUoH4LPsGq7JDs.jpg");
        request.setDriverLicenseFrontImg("https://file.test.com/test/oxG12YsjYHryHGYF2eBUoH4LPsGq7JDs.jpg");
        request.setDriverLicenseBackImg("https://file.test.com/test/oxG12YsjYHryHGYF2eBUoH4LPsGq7JDs.jpg");
        request.setDriverCardStartLine("20270131");
        request.setProfessionalQualificationCertificateImg("https://file.test.com/test/oxG12YsjYHryHGYF2eBUoH4LPsGq7JDs.jpg");
        request.setDriverAgreementUrl("https://file.test.com/test/oxG12YsjYHryHGYF2eBUoH4LPsGq7JDs.jpg");
        //步骤三: 调用服务

        Result<?> result = reportClient.reportDriver(request);
        //步骤四: 拿到结果
        System.out.println(JSONObject.toJSONString(result, JSONWriter.Feature.PrettyFormat));
    }


    //运单上报
    private static void reportWaybill() {
        //步骤二: 选择服务
        ReportClient reportClient = CLIENT_MANAGER.use(ReportClient.class);
        ReportWaybillRequest request = new ReportWaybillRequest();
        request.setActualCarrierBusinessLicense("140227006170");
        request.setActualCarrierId("140225198101174612");
        request.setActualCarrierName("王春");
        request.setArrivalTicketFileUrl("https://file.test.com/HVX2xnijNapiVH3dICMAiStD8EFo21LK.jpg,https://file.test.com/7wT8GXyiNipm3l9uQKo40s3JG1civkaT.jpg,https://file.test.com/Vm8M2eTngk8Hi50WciNkslCAOzW7WkRr.jpg,https://file.test.com/0rskbbqDvtBnoHuLlfmPq3fKtkGwNRTB.jpg,https://file.test.com/MeOyOkl1q415LJA8H75jwUP6a9LeGTE5.jpg");
        request.setArrivalTime("20240621091103");
        request.setBodyId("管理员分配的bodyId");
        request.setBusinessTypeCode(BusinessTypeEnum.GANXIAN);
        request.setCommercialContractNumber("17240617165360004");
        request.setConsignee("无");
        request.setConsigneeId("000000000000000000");
        request.setConsignmentDateTime("20240617140558");
        request.setConsignor("江苏XXXXXX物流有限公司");
        request.setConsignorId("91320206331084042L");
        request.setConsignorImg("https://file.test.com/I0XNfM5kR1EvvSG1XlMxI5pOI6wWfDy4.jpg");
        request.setContractNumber("16240617165233003");
        request.setDeliverCity("广州市");
        request.setDeliverCounty("南沙区");
        request.setDeliverLat("22.835591");
        request.setDeliverLon("113.546697");
        request.setDeliverProvince("广东省");
        request.setDepartureTime("20240618073103");
        request.setDespatchActualDateTime("20240618073103");
        request.setDriverName("王春");
        request.setDrivingLicense("140225198101174612");
        request.setEtcFileUrl("");
        request.setGoodsArrangementTypeCode(GoodsTransportTypeEnum.GOODS_TRANSPORT_TYPE_100);

        ReportWaybillRequest.GoodsInfoDomain goodsInfoDomain = new ReportWaybillRequest.GoodsInfoDomain();
        goodsInfoDomain.setCargoTypeClassificationCode(GoodsTypeEnum.OTHER);
        goodsInfoDomain.setDescriptionOfGoods("润滑油");
        goodsInfoDomain.setGoodsItemGrossWeight(new BigDecimal("6.5"));
        request.setGoodsInfo(Arrays.asList(goodsInfoDomain));
        request.setGoodsReceiptDateTime("20240623170341");
        request.setGoodsReceiptPlace("大同市通用汽配城-北区");
        request.setIsLocalCity(false);
        request.setLinkPerson("江苏XXXXXX物流有限公司");
        request.setLinkPhone("15370255911");
        request.setPlaceOfLoading("路路达XXXX有限公司");
        request.setReceivingCity("大同市");
        request.setReceivingCounty("平城区");
        request.setReceivingLat("40.058401");
        request.setReceivingLon("113.254301");
        request.setReceivingProvince("山西省");
        request.setShippingNoteNumber("10240617162059157");
        request.setStartTicketFileUrl("https://file.test.com/D0BxtJcjJLd98rfzeyeqaC7HyQ9mYmpX.jpg,https://file.test.com/AaC5Trk9TZ1a9ECNe8S2YxqClVkUVIPw.jpg,https://file.test.com/YW8nsKY2yxwCcQ0T7ar0Yyn4XrFkS3Ki.jpg,https://file.test.com/C9i4aBUbB2m2beISl5XvFQc7EXZipPCo.jpg,https://file.test.com/2hMv1pJfQoqNeklc8Ppfb5y7JZCoPvga.jpg");
        request.setTotalDriverFreight("10500.000");
        request.setTotalMonetaryAmount("11099.370");
        request.setTransportTypeCode(TransportTypeEnum.ROAD_TRANSPORT);
        request.setVehicleAmount(1);
        request.setVehicleNumber("晋BJ8683");
        request.setVehiclePlateColorCode(CarColorEnum.YELLOW);
        request.setWaybillFreightAmount("10500.000");

        //步骤三: 调用服务
        Result<?> result = reportClient.reportWaybill(request);
        //步骤四: 拿到结果
        System.out.println(JSONObject.toJSONString(result, JSONWriter.Feature.PrettyFormat));
    }


    //合同上报
    private static void reportContract() {
        //委托合同
        //步骤二: 选择服务
        ReportClient reportClient = CLIENT_MANAGER.use(ReportClient.class);

        ReportContractRequest request = new ReportContractRequest();

        request.setAgreedBusinessCompletionTime(new Date());
        request.setBankName("");
        request.setBodyId("管理员分配的bodyId");
        request.setBusinessActualCompletionTime(new Date());
        request.setContractAmount(new BigDecimal("11099.37"));
        request.setContractBusinessName("委托合同");
        request.setContractNumber("16240617165233003");
        request.setContractSigningTime(new Date());
        request.setContractType(ContractTypeEnum.OWNER);
        request.setContractUrl("https://file.test.com/neEJvuwXSFbTDMcewJusXWlPQ2DzYHUX.pdf");
        request.setContractedCarryingCapacity(BigDecimal.ONE);
        request.setPartyAAccount("");
        request.setPartyABankName("");
        request.setPartyAId("91320206331084042L");
        request.setPartyAName("江苏XXXXXX物流有限公司");
        request.setPartyBAccount("");
        request.setPartyBBankName("");
        request.setPartyBId("91340800MA2UAL1D2X");
        request.setPartyBName("安庆XXXX发展有限公司");
        request.setPartyBReceiptName("");
        request.setPaymentAmount(new BigDecimal("11099.37"));
        request.setPromisePayTime(new Date());
        request.setServiceCharge("");
        request.setShippingNoteNumber("10240617162059157");
        request.setUnit("车");

        //步骤三: 调用服务
        Result<?> result = reportClient.reportContract(request);
        System.out.println(JSONObject.toJSONString(result, JSONWriter.Feature.PrettyFormat));

        if (result.isSuccess()) {
            //承运合同
            ReportContractRequest request2 = new ReportContractRequest();
            request2.setAgreedBusinessCompletionTime(new Date());
            request2.setBankName("");
            request2.setBodyId("管理员分配的bodyId");
            request2.setBusinessActualCompletionTime(new Date());
            request2.setContractAmount(new BigDecimal("10500"));
            request2.setContractBusinessName("承运合同");
            request2.setContractNumber("17240617165360004");
            request2.setContractSigningTime(new Date());
            request2.setContractType(ContractTypeEnum.CARRIER);
            request2.setContractUrl("https://file.test.com/TKOw86nRI8NhzxKbJuqB6XrK48QIbOEf.pdf");
            request2.setContractedCarryingCapacity(BigDecimal.ONE);
            request2.setPartyAAccount("");
            request2.setPartyABankName("");
            request2.setPartyAId("91340800MA2UAL1D2X");
            request2.setPartyAName("安庆XXXX发展有限公司");
            request2.setPartyBAccount("");
            request2.setPartyBBankName("");
            request2.setPartyBId("140225198101174612");
            request2.setPartyBName("王春");
            request2.setPartyBReceiptName("");
            request2.setPaymentAmount(new BigDecimal("10500"));
            request2.setPromisePayTime(new Date());
            request2.setServiceCharge("");
            request2.setShippingNoteNumber("10240617162059157");
            request2.setUnit("车");

            //步骤三: 调用服务
            Result<?> result2 = reportClient.reportContract(request2);
            System.out.println(JSONObject.toJSONString(result2, JSONWriter.Feature.PrettyFormat));
        }

        //步骤四: 拿到结果

    }


    //轨迹上报
    private static void reportTrack() {
        //步骤二: 选择服务
        ReportClient reportClient = CLIENT_MANAGER.use(ReportClient.class);

        ReportTrackRequest request = new ReportTrackRequest();
        request.setBodyId("管理员分配的bodyId");
        request.setShippingNoteNumber("10240617162059157");
        //设置参数
        //......

        //步骤三: 调用服务
        Result<?> result = reportClient.reportTrack(request);
        //步骤四: 拿到结果
        System.out.println(JSONObject.toJSONString(result, JSONWriter.Feature.PrettyFormat));
    }


    //支付流水上报
    private static void reportFinancial() {
        //步骤二: 选择服务
        ReportClient reportClient = CLIENT_MANAGER.use(ReportClient.class);
        ReportFinancialRequest request = new ReportFinancialRequest();
        request.setBodyId("管理员分配的bodyId");
        request.setShippingNoteNumber("10240617162059157");
        ReportFinancialRequest.Financial carrier = new ReportFinancialRequest.Financial();
        carrier.setActualCarrierId("140225198101174612");
        carrier.setAppointmentTime(new Date());
        carrier.setCarrier("王春");
        carrier.setDocumentNumber("202406221659210348568176843");
        carrier.setFinancialType(FinancialTypeEnum.CARRIER);
        carrier.setMonetaryAmount(new BigDecimal("10500"));
        carrier.setPayTime(new Date());
        carrier.setPaymentAccount("15550327930095");
        carrier.setPaymentBankName("平安银行合肥分行营业部");
        carrier.setPaymentMeansCode(PaymentTypeEnum.BANK_TRANSFER);
        carrier.setPaymentName("安庆XXXX发展有限公司");
        carrier.setReceiptAccount("6228480918276893677");
        carrier.setReceiptBankCode("ABOC");
        carrier.setReceiptBankName("中国农业银行");
        carrier.setReceiptIdCard("140225198101174612");
        carrier.setRecipient("王春");
        carrier.setSequenceCode("8043432406222461538689");
        carrier.setStatementType(1);

        ReportFinancialRequest.Financial owner = new ReportFinancialRequest.Financial();
        owner.setActualCarrierId("91320206331084042L");
        owner.setAppointmentTime(new Date());
        owner.setCarrier("江苏XXXXXX物流有限公司");
        owner.setDocumentNumber("202406221659210221737957461");
        owner.setFinancialType(FinancialTypeEnum.OWNER);
        owner.setMonetaryAmount(new BigDecimal("599.37"));
        owner.setPayTime(new Date());
        owner.setPaymentAccount("W921189345205903068");
        owner.setPaymentBankName("平安银行");
        owner.setPaymentMeansCode(PaymentTypeEnum.BANK_TRANSFER);
        owner.setPaymentName("江苏XXXXXX物流有限公司");
        owner.setReceiptAccount("15550327930095");
        owner.setReceiptBankCode("SZDB");
        owner.setReceiptBankName("平安银行合肥分行营业部");
        owner.setReceiptIdCard("91320206331084042L");
        owner.setRecipient("安庆XXXX发展有限公司");
        owner.setSequenceCode("8043432406220461529078");
        owner.setStatementType(2);
        request.setFinancialList(Arrays.asList(carrier, owner));
        Result<?> result = reportClient.reportFinancial(request);
        //步骤四: 拿到结果
        System.out.println(JSONObject.toJSONString(result, JSONWriter.Feature.PrettyFormat));
    }
}
